package com.axend.aerosense.room.ui.activity;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;

import androidx.fragment.app.Fragment;

import com.axend.aerosense.base.activity.MvvmBaseActivity;
import com.axend.aerosense.base.bean.RoomTypeBean;
import com.axend.aerosense.base.viewmodel.BaseViewModel;
import com.axend.aerosense.common.base.IToolBarTextClickListence;
import com.axend.aerosense.common.util.FragmentUtil;
import com.axend.aerosense.room.R;
import com.axend.aerosense.room.databinding.RoomActivityEditBinding;
import com.axend.aerosense.room.databinding.RoomActivitySaveModelBinding;
import com.axend.aerosense.room.ui.fragment.RoomEditFragment;
import com.axend.aerosense.room.ui.fragment.RoomNameFragment;
import com.axend.aerosense.room.ui.fragment.RoomTypeListFragment;
import com.gyf.immersionbar.ImmersionBar;

public class RoomEditActivity extends MvvmBaseActivity<RoomActivityEditBinding, BaseViewModel> {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ImmersionBar.with(this)
                .statusBarColor(android.R.color.white)
                .fitsSystemWindows(true)
                .statusBarDarkFont(true)
                .autoDarkModeEnable(true).init();
        setSupportActionBar(viewDataBinding.roomToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);//左侧添加一个默认的返回图标
        getSupportActionBar().setHomeButtonEnabled(true); //设置返回键可用
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        Fragment currentFragment = RoomEditFragment.getInstance();
        FragmentUtil.add(this, viewDataBinding.roomContent.getId(), currentFragment, null, false);
    }

    public void setRightText(int str, View.OnClickListener listener){
        viewDataBinding.roomToolbar.setMySettingText(str);
        viewDataBinding.roomToolbar.setRightTitleVisibility(View.VISIBLE);
        viewDataBinding.roomToolbar.setRightTitleClickable(true);
        viewDataBinding.roomToolbar.setSettingTextOnClickListener(listener);
    }

    public void setTitle(String title) {
        viewDataBinding.roomTitle.setText(title);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            onBackPressed();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
            finish();
            return;
        }
//        FragmentUtils.show(getSupportFragmentManager());
        super.onBackPressed();
    }

    @Override
    protected BaseViewModel getViewModel() {
        return null;
    }

    @Override
    protected int getBindingVariable() {
        return 0;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.room_activity_edit;
    }

    @Override
    protected void onRetryBtnClick() {

    }
}